﻿using System;

namespace Patterns.FactoryMethod {
    public static class AbstractExample {

        public static void Run() {
            // An array of creators
            Creator[] creators = {
                new ConcreteCreatorA(),
                new ConcreteCreatorB()};

            // Iterate over creators and create products
            foreach (Creator creator in creators) {
                Product product = creator.FactoryMethod();
                Console.WriteLine("Created {0}",
                  product.GetType().Name);
            }
        }
    }

    // "Product"
    abstract class Product { }

    // "ConcreteProductA"
    class ConcreteProductA : Product { }

    // "ConcreteProductB"
    class ConcreteProductB : Product { }

    // "Creator"
    abstract class Creator {
        public abstract Product FactoryMethod();
    }

    // "ConcreteCreator"
    class ConcreteCreatorA : Creator {
        public override Product FactoryMethod() {
            return new ConcreteProductA();
        }
    }

    // "ConcreteCreator"
    class ConcreteCreatorB : Creator {
        public override Product FactoryMethod() {
            return new ConcreteProductB();
        }
    }
}
